/******************************************************************************
 * FileName:    gwin_motor_task.h
 * Desc:        电机任务
 *
 *
 * Author:      Lin
 * Notes:
 *
 ******************************************************************************/

#ifndef _GWIN_MOTOR_TASK_H_
#define _GWIN_MOTOR_TASK_H_


/*-------------------------- Includes ---------------------------------------*/
#include "gwin_global_config.h"


/*-------------------------- Macro Definitions ------------------------------*/

/*-------------------------- Type Declarations ------------------------------*/
/**
 * @brief 消息
 */
typedef struct
{
    uint16_t type;
    uint16_t subtype;
    union
    {
        // 设置参数
        struct
        {
            uint8_t action_type;
            uint8_t reserve1;
            uint16_t reserve2;
            uint32_t cfg_value;
        };
        // 电机更新
        struct
        {
            uint8_t target_position;
        };
    };
}gwin_motor_task_msg_t;

/**
 * @brief 消息类型
 */
typedef enum
{
    MOTOR_TASK_MSG_TYPE_NONE,
    MOTOR_TASK_MSG_TYPE_TASK_INIT,
    MOTOR_TASK_MSG_TYPE_CFG,
    MOTOR_TASK_MSG_TYPE_TIMER,
    MOTOR_TASK_MSG_TYPE_MOTOR,
}gwin_motor_task_msg_type_t;

/**
 * @brief 设置动作类型
 */
typedef enum
{
    MOTOR_TASK_MSG_CFG_ACT_TYPE_NONE,
    MOTOR_TASK_MSG_CFG_ACT_TYPE_SET,
    MOTOR_TASK_MSG_CFG_ACT_TYPE_GET,
}gwin_motor_task_msg_cfg_action_type_t;

/**
 * @brief 设置消息子类型
 */
typedef enum
{
    MOTOR_TASK_MSG_CFG_SUBTYPE_NONE,
}gwin_motor_task_msg_cfg_subtype_t;

/**
 * @brief 定时器消息子类型
 */
typedef enum
{
    MOTOR_TASK_MSG_TIMER_SUBTYPE_NONE,
    MOTOR_TASK_MSG_TIMER_SUBTYPE_GRADUAL,
}gwin_motor_task_msg_timer_subtype_t;

/**
 * @brief 电机子类型
 */
typedef enum
{
    MOTOR_TASK_MSG_MOTOR_SUBTYPE_NONE,
    MOTOR_TASK_MSG_MOTOR_SUBTYPE_START,
    MOTOR_TASK_MSG_MOTOR_SUBTYPE_STOP,
}gwin_motor_task_msg_motor_subtype_t;


/**
 * @brief 目标参数
 */
typedef struct
{
    uint8_t state               : 1;    // 开始停止状态
    uint32_t reserve[8];                // 保留
}motor_target_t;



/*-------------------------- Global Variables -------------------------------*/

/*-------------------------- Local Variables --------------------------------*/

/*-------------------------- Functions Declarations -------------------------*/

/*-------------------------- Functions Definitions --------------------------*/
void gwin_motor_task_init(void);
#define gwin_send_msg_to_motor_task(p_msg)           os_msg_send(gwin_motor_task, p_msg)

void gwin_motor_run_start(uint8_t target_position);
void gwin_motor_run_stop(void);

void gwin_motor_encoder_handle(void);


#endif // _GWIN_MOTOR_TASK_H_


/*-------------------------- END OF FILE ------------------------------------*/

